package com.newer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newer.dao.MemberMapper;
import com.newer.domain.Member;
import com.newer.dto.PageDto;
import com.newer.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    MemberMapper memberMapper;

    @Override
    public List<Member> LoginByName(String name, String pwd) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("name",name);
        map.put("pwd",pwd);

        List<Member> list=this.memberMapper.selectByMap(map);

        if(list!=null){
            return list;
        }
        return null;
    }

    @Override
    public IPage<Member> selectMember(PageDto pageDto) {
        Page<Member> page=new Page<>(pageDto.getPage(),pageDto.getPageSize());
        IPage<Member> ipage=this.memberMapper.selectPage(page,null);
        return ipage;
    }

    @Override
    public void deleteMemberById(Integer id) {
        this.memberMapper.deleteById(id);
    }

    @Override
    public List<Member> selectByParam(String param) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.like("name",param);
        return this.memberMapper.selectList(queryWrapper);
    }
}
